package com.ruoyi.edu.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.edu.domain.EduMenu;
import com.ruoyi.edu.service.IEduMenuService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 菜单名Controller
 * 
 * @author ruoyi
 * @date 2023-05-06
 */
@Controller
@RequestMapping("/edu/menu")
public class EduMenuController extends BaseController
{
    private String prefix = "edu/menu";

    @Autowired
    private IEduMenuService eduMenuService;

    @RequiresPermissions("edu:menu:view")
    @GetMapping()
    public String menu()
    {
        return prefix + "/menu";
    }

    /**
     * 查询菜单名列表
     */
    @RequiresPermissions("edu:menu:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(EduMenu eduMenu)
    {
        startPage();
        List<EduMenu> list = eduMenuService.selectEduMenuList(eduMenu);
        return getDataTable(list);
    }

    /**
     * 导出菜单名列表
     */
    @RequiresPermissions("edu:menu:export")
    @Log(title = "菜单名", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(EduMenu eduMenu)
    {
        List<EduMenu> list = eduMenuService.selectEduMenuList(eduMenu);
        ExcelUtil<EduMenu> util = new ExcelUtil<EduMenu>(EduMenu.class);
        return util.exportExcel(list, "菜单名数据");
    }

    /**
     * 新增菜单名
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存菜单名
     */
    @RequiresPermissions("edu:menu:add")
    @Log(title = "菜单名", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(EduMenu eduMenu)
    {
        return toAjax(eduMenuService.insertEduMenu(eduMenu));
    }

    /**
     * 修改菜单名
     */
    @RequiresPermissions("edu:menu:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        EduMenu eduMenu = eduMenuService.selectEduMenuById(id);
        mmap.put("eduMenu", eduMenu);
        return prefix + "/edit";
    }

    /**
     * 修改保存菜单名
     */
    @RequiresPermissions("edu:menu:edit")
    @Log(title = "菜单名", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(EduMenu eduMenu)
    {
        return toAjax(eduMenuService.updateEduMenu(eduMenu));
    }

    /**
     * 删除菜单名
     */
    @RequiresPermissions("edu:menu:remove")
    @Log(title = "菜单名", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(eduMenuService.deleteEduMenuByIds(ids));
    }
}
